package com.jshoperxms.controller.mall.backstage.dashboard;

import com.jshoperxms.Response;
import com.jshoperxms.controller.mall.backstage.base.BaseTController;
import com.jshoperxms.controller.utils.BaseTools;
import com.jshoperxms.controller.utils.DateTools;
import com.jshoperxms.controller.utils.enums.BaseEnums;
import com.jshoperxms.controller.utils.statickey.SerialKeys;
import com.jshoperxms.controller.utils.statickey.TagWords;
import com.jshoperxms.entity.*;
import com.jshoperxms.service.FaqArticlesTService;
import com.jshoperxms.service.MemberTService;
import com.jshoperxms.service.OrderTService;
import com.jshoperxms.service.ProductTService;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by sdywcd on 17/1/3.
 * Des:
 */
@Controller
@RequestMapping("/mall/dashboard")
public class DashboradController extends BaseTController {

    //数据形式
    private Map<String, Object> responsedata = new HashMap<>();


    @Resource
    private ProductTService productTService;

    @Resource
    private MemberTService memberTService;

    @Resource
    private OrderTService orderTService;

    @Resource
    private FaqArticlesTService faqArticlesTService;

    @RequestMapping(value="/dashboard",method= RequestMethod.POST)
    public ResponseEntity dashboard() {
        Criterion criterion= Restrictions.ne(TagWords.STATUS, BaseEnums.DataUsingState.DEL.getState());
        int amountproducts=this.productTService.count(ProductT.class,criterion).intValue();
        int amountmembers=this.memberTService.count(MemberT.class,criterion).intValue();
        //int amountorders=this.orderTService.count(OrderT.class,criterion).intValue();
        int amountfaqs=this.faqArticlesTService.count(FaqArticlesT.class,criterion).intValue();
        responsedata.put("amountfaqs",amountfaqs);
        //responsedata.put("amountorders",amountorders);
        responsedata.put("amountmembers",amountmembers);
        responsedata.put("amountproducts",amountproducts);
        responsedata.put(TagWords.SUCCESS, true);
        responsedata.put(TagWords.MSG,TagWords.OPERATION_SUCCESS);
        return Response.success(responsedata);
    }
}
